package cdautils;


/**
 * Represents a single Triage-Tag document.
 * @author Felix
 * 
 */

import java.util.GregorianCalendar;

import java.util.Calendar;
import java.util.HashMap;
import java.util.Map.Entry;

public class TriageTag {
	
	//Document basics
	private String document_uid;
	private Integer document_vnr;
	
	private String document_parent_uid;
	private Integer document_parent_vnr;
	private GregorianCalendar effectiveTime;
	
	//Patient basics
	private String given;
	private String family;
	private Gender gender;
	private GregorianCalendar birthdate;
	
	//Document author
	private String author_uid;
	private String author_given;
	private String author_family;

	//Mandatory fields
	private Boolean gehfaehigkeit;
	private Stability respiration;
	private Stability perfusion;
	private Stability mentalerstatus;
	private TreatmentStatus behandlungsstatus;
	private TriageCategory triagekategorie;
	
	//Optional fields
	private Double gps_longitude;
	private Double gps_latitude;
	private Double gps_accuracy;
	private PhaseOfLife lebensphase;
	private String hilfplatzposition;
	private String bergeinformation;
	private Integer urgency;
	private String diagnosis;
	private Integer blood_pressure_systolic;
	private Integer blood_pressure_diastolic;
	private Integer puls;
	private String behandlungsverlauf;
	private Boolean transportbereitschaft;
	private String zielkrankenhaus;
	private String krankenkasse;
	
	//Bodypart, injury
	private HashMap<BodyPart, String> verletzungen;
	
	//Quick Constructor for Android
	public TriageTag() {
		this.verletzungen = new HashMap<BodyPart, String>();
	}
	
	//Only mandatory fields
	public TriageTag(String document_uid, Integer document_vnr, String document_parent_uid, Integer document_nr, GregorianCalendar effectiveTime, String given, String family, Gender gender, GregorianCalendar birthdate, String author_uid, Boolean gehfaehigkeit, Stability respiration, Stability perfusion, Stability mentalerstatus, TreatmentStatus behandlungsstatus, TriageCategory triagekategorie) {
		super();
		this.document_uid = document_uid;
		this.document_vnr = document_vnr;
		this.document_parent_uid = document_parent_uid;
		this.document_parent_vnr = document_nr;
		this.effectiveTime = effectiveTime;
		this.given = given;
		this.family = family;
		this.gender = gender;
		this.birthdate = birthdate;
		this.author_uid = author_uid;
		this.gehfaehigkeit = gehfaehigkeit;
		this.respiration = respiration;
		this.perfusion = perfusion;
		this.mentalerstatus = mentalerstatus;
		this.behandlungsstatus = behandlungsstatus;
		this.triagekategorie = triagekategorie;
		
		this.verletzungen = new HashMap<BodyPart, String>();
	}
	
	//Only mandatory fields + author-name
	public TriageTag(String document_uid, Integer document_vnr, String document_parent_uid, Integer document_nr, GregorianCalendar effectiveTime, String given, String family, Gender gender, GregorianCalendar birthdate, String author_uid, String author_given, String author_family, Boolean gehfaehigkeit, Stability respiration, Stability perfusion, Stability mentalerstatus, TreatmentStatus behandlungsstatus, TriageCategory triagekategorie) {
		this(document_uid, document_vnr, document_parent_uid, document_nr, effectiveTime, given, family, gender, birthdate, author_uid, gehfaehigkeit, respiration, perfusion, mentalerstatus, behandlungsstatus, triagekategorie);
		this.author_given = author_given;
		this.author_family = author_family;
	}
	
	//Also optional fields
	public TriageTag(String document_uid, Integer document_vnr, String document_parent_uid,
			Integer document_nr, GregorianCalendar effectiveTime, String given,
			String family, Gender gender, GregorianCalendar birthdate,
			String author_uid, Boolean gehfaehigkeit, Stability respiration,
			Stability perfusion, Stability mentalerstatus,
			TreatmentStatus behandlungsstatus, TriageCategory triagekategorie,
			Double gps_longitude, Double gps_latidue, Double gps_accuracy,
			PhaseOfLife lebensphase, String hilfplatzposition, 
			String bergeinformation, Integer urgency, String diagnosis,
			Integer blood_pressure_systolic, Integer blood_pressure_diastolic, Integer puls,
			String behandlungsverlauf, Boolean transportbereitschaft,
			String zielkrankenhaus, String krankenkasse) {
		this(document_uid, document_vnr, document_parent_uid, document_nr, effectiveTime, given, family, gender, birthdate, author_uid, gehfaehigkeit, respiration, perfusion, mentalerstatus, behandlungsstatus, triagekategorie);
		this.gps_longitude = gps_longitude;
		this.gps_latitude = gps_latidue;
		this.gps_accuracy = gps_accuracy;
		this.lebensphase = lebensphase;
		this.bergeinformation = bergeinformation;
		this.hilfplatzposition = hilfplatzposition;
		this.urgency = urgency;
		this.diagnosis = diagnosis;
		this.blood_pressure_systolic = blood_pressure_systolic;
		this.blood_pressure_diastolic = blood_pressure_diastolic;
		this.puls = puls;
		this.behandlungsverlauf = behandlungsverlauf;
		this.transportbereitschaft = transportbereitschaft;
		this.zielkrankenhaus = zielkrankenhaus;
		this.krankenkasse = krankenkasse;
	}
	
	//Also optional fields + author name
	public TriageTag(String document_uid, Integer document_vnr, String document_parent_uid,
			Integer document_nr, GregorianCalendar effectiveTime, String given,
			String family, Gender gender, GregorianCalendar birthdate,
			String author_uid, String author_given, String author_family, Boolean gehfaehigkeit, Stability respiration,
			Stability perfusion, Stability mentalerstatus,
			TreatmentStatus behandlungsstatus, TriageCategory triagekategorie,
			Double gps_longitude, Double gps_latidue, Double gps_accuracy,
			PhaseOfLife lebensphase, String hilfplatzposition, 
			String bergeinformation, Integer urgency, String diagnosis,
			Integer blood_pressure_systolic, Integer blood_pressure_diastolic, Integer puls,
			String behandlungsverlauf, Boolean transportbereitschaft,
			String zielkrankenhaus, String krankenkasse) {
		this(document_uid, document_vnr, document_parent_uid, document_nr, effectiveTime, given, family, gender, birthdate, author_uid, author_given, author_family, gehfaehigkeit, respiration, perfusion, mentalerstatus, behandlungsstatus, triagekategorie);
		this.gps_longitude = gps_longitude;
		this.gps_latitude = gps_latidue;
		this.gps_accuracy = gps_accuracy;
		this.lebensphase = lebensphase;
		this.bergeinformation = bergeinformation;
		this.hilfplatzposition = hilfplatzposition;
		this.urgency = urgency;
		this.diagnosis = diagnosis;
		this.blood_pressure_systolic = blood_pressure_systolic;
		this.blood_pressure_diastolic = blood_pressure_diastolic;
		this.puls = puls;
		this.behandlungsverlauf = behandlungsverlauf;
		this.transportbereitschaft = transportbereitschaft;
		this.zielkrankenhaus = zielkrankenhaus;
		this.krankenkasse = krankenkasse;
	}
	
	public String getDocument_uid() {
		return document_uid;
	}

	public void setDocument_uid(String document_uid) {
		this.document_uid = document_uid;
	}
	
	public int getDocument_vnr() {
		return document_vnr;
	}

	public void setDocument_vnr(Integer document_nr) {
		this.document_vnr = document_nr;
	}
	

	public String getDocument_parent_uid() {
		return document_parent_uid;
	}

	public void setDocument_parent_uid(String document_parent_uid) {
		this.document_parent_uid = document_parent_uid;
	}

	public int getDocument_parent_vnr() {
		return document_parent_vnr;
	}

	public void setDocument_parent_vnr(Integer document_nr) {
		this.document_parent_vnr = document_nr;
	}
	
	public GregorianCalendar getEffectiveTime() {
		return effectiveTime;
	}

	public void setEffectiveTime(GregorianCalendar effectiveTime) {
		this.effectiveTime = effectiveTime;
	}

	public String getGiven() {
		return given;
	}

	public void setGiven(String given) {
		this.given = given;
	}

	public String getFamily() {
		return family;
	}

	public void setFamily(String family) {
		this.family = family;
	}

	public Gender getGender() {
		return gender;
	}

	public void setGender(Gender gender) {
		this.gender = gender;
	}

	public GregorianCalendar getBirthdate() {
		return birthdate;
	}

	public void setBirthdate(GregorianCalendar birthdate) {
		this.birthdate = birthdate;
	}

	public String getAuthor_uid() {
		return author_uid;
	}

	public void setAuthor_uid(String author_uid) {
		this.author_uid = author_uid;
	}
	
	public String getAuthor_given() {
		return author_given;
	}

	public void setAuthor_given(String author_given) {
		this.author_given = author_given;
	}

	public String getAuthor_family() {
		return author_family;
	}

	public void setAuthor_family(String author_family) {
		this.author_family = author_family;
	}

	public Boolean getGehfaehigkeit() {
		return gehfaehigkeit;
	}

	public void setGehfaehigkeit(Boolean gehfaehigkeit) {
		this.gehfaehigkeit = gehfaehigkeit;
	}

	public Stability getRespiration() {
		return respiration;
	}

	public void setRespiration(Stability respiration) {
		this.respiration = respiration;
	}

	public Stability getPerfusion() {
		return perfusion;
	}

	public void setPerfusion(Stability perfusion) {
		this.perfusion = perfusion;
	}

	public Stability getMentalerstatus() {
		return mentalerstatus;
	}

	public void setMentalerstatus(Stability mentalerstatus) {
		this.mentalerstatus = mentalerstatus;
	}
	
	public TreatmentStatus getBehandlungsstatus() {
		return behandlungsstatus;
	}

	public void setBehandlungsstatus(TreatmentStatus behandlungsstatus) {
		this.behandlungsstatus = behandlungsstatus;
	}

	public TriageCategory getTriagekategorie() {
		return triagekategorie;
	}

	public void setTriagekategorie(TriageCategory triagekategorie) {
		this.triagekategorie = triagekategorie;
	}

	public Double getGps_longitude() {
		return gps_longitude;
	}

	public void setGps_longitude(Double gps_longitude) {
		this.gps_longitude = gps_longitude;
	}

	public Double getGps_latitude() {
		return gps_latitude;
	}

	public void setGps_latitude(Double gps_latidue) {
		this.gps_latitude = gps_latidue;
	}

	public Double getGps_accuracy() {
		return gps_accuracy;
	}

	public void setGps_accuracy(Double gps_accuracy) {
		this.gps_accuracy = gps_accuracy;
	}

	public PhaseOfLife getLebensphase() {
		return lebensphase;
	}

	public void setLebensphase(PhaseOfLife lebensphase) {
		this.lebensphase = lebensphase;
	}

	public String getBergeinformation() {
		return bergeinformation;
	}

	public void setBergeinformation(String bergeinformation) {
		this.bergeinformation = bergeinformation;
	}

	public String getHilfplatzposition() {
		return hilfplatzposition;
	}

	public void setHilfplatzposition(String hilfplatzposition) {
		this.hilfplatzposition = hilfplatzposition;
	}

	public Integer getUrgency() {
		return urgency;
	}

	public void setUrgency(Integer urgency) {
		this.urgency = urgency;
	}

	public String getDiagnosis() {
		return diagnosis;
	}

	public void setDiagnosis(String diagnosis) {
		this.diagnosis = diagnosis;
	}

	public Integer getBlood_pressure_systolic() {
		return blood_pressure_systolic;
	}

	public void setBlood_pressure_systolic(Integer blood_pressure_systolic) {
		this.blood_pressure_systolic = blood_pressure_systolic;
	}

	public Integer getBlood_pressure_diastolic() {
		return blood_pressure_diastolic;
	}

	public void setBlood_pressure_diastolic(Integer blood_pressure_diastolic) {
		this.blood_pressure_diastolic = blood_pressure_diastolic;
	}
	
	public Integer getPuls() {
		return puls;
	}

	public void setPuls(Integer puls) {
		this.puls = puls;
	}

	public String getBehandlungsverlauf() {
		return behandlungsverlauf;
	}

	public void setBehandlungsverlauf(String behandlungsverlauf) {
		this.behandlungsverlauf = behandlungsverlauf;
	}

	public Boolean getTransportbereitschaft() {
		return transportbereitschaft;
	}

	public void setTransportbereitschaft(Boolean transportbereitschaft) {
		this.transportbereitschaft = transportbereitschaft;
	}

	public String getZielkrankenhaus() {
		return zielkrankenhaus;
	}

	public void setZielkrankenhaus(String zielkrankenhaus) {
		this.zielkrankenhaus = zielkrankenhaus;
	}

	public String getKrankenkasse() {
		return krankenkasse;
	}

	public void setKrankenkasse(String krankenkasse) {
		this.krankenkasse = krankenkasse;
	}

	public final HashMap<BodyPart, String> getVerletzungen() {
		return verletzungen;
	}
	
	public void setVerletzungen(HashMap<BodyPart, String> verletzungen) {
		this.verletzungen = verletzungen;
	}

	public void setVerletzung(BodyPart bp, String str) {
		verletzungen.put(bp, str);
	}
	
	public void removeVerletzung(BodyPart bp) {
		verletzungen.remove(bp);
	}
	
	/**
	 * This method will try to integrate a older document into the document's version-history.
	 * Example: If a emergency worker modifies a document with the document_nr 2 (resulting in document_nr 3
	 * of the very same document), but cannot transmit the changes to the Triage-Serve due network-problems the
	 * document can be transmitted later. But if the document was updated in between and now (for example) is 
	 * already available with the document_nr 6, this method will try to create a new document with document_nr 7,
	 * containing the changes from the emergency worker's document with the document_nr 3.
	 * 
	 * Changed data-fields of the older document will only be applied if no newer version of the document
	 * has overwritten the specific field.
	 * 
	 * @param history History of a document, if newTag's document_nr is i and n is the newest document in DB, then history should contain all documents from i-1 until n.
	 * @param newTag Tag to integrate in document history
	 * @return A instance of TriageTag with the changes from newTag integrated, or NULL if nothing can be integrated.
	 */
	public static TriageTag integrateChanges(TriageTag[] history, final TriageTag newTag) {
		
		
		boolean changes[] = new boolean[26];
		boolean changesHist[] = new boolean[26];
		
		//Create list of changes from oldest Tag to "newTag",
		//which should be the subsequently added successor of the oldestTag.
		changes = difference(changes,history[0],newTag);
		
		//Create "list of all changes through history" AND remove "outdated" injuries
		for (int i = 0; i < history.length-1; i++) {
			
			TriageTag t1 = history[i];
			TriageTag t2 = history[i+1];
			
			//Newer versions of the same document OVERWRITE OR REMOVE injuries from
			//newTag if they have been overwitten once
			for (Entry<BodyPart,String> entry : history[i+1].getVerletzungen().entrySet()) {
				newTag.removeVerletzung(entry.getKey());
			}
			
			changesHist = difference(changesHist,t1,t2);

		}
		
		TriageTag tNewest = history[history.length-1];
		
		//If this stays false, no changes have to be written to DB
		//hence newTag will be "dropped"
		boolean needToUpdate = false;
		
		if (changes[0] && !changesHist[0]) {
			needToUpdate = true;
			tNewest.given = newTag.given;
		}
		if (changes[1] && !changesHist[1]) {
			needToUpdate = true;
			tNewest.family = newTag.family;
		}
		if (changes[2] && !changesHist[2]) {
			needToUpdate = true;
			tNewest.gender = newTag.gender;
		}
		if (changes[3] && !changesHist[3]) {
			needToUpdate = true;
			tNewest.birthdate = newTag.birthdate;
		}
		//Does not matter
		/*if (changes[4] && !changesHist[4]) {
			needToUpdate = true;
			tNewest.author_uid = newTag.author_uid;
		}*/
		if (changes[5] && !changesHist[5]) {
			needToUpdate = true;
			tNewest.gehfaehigkeit = newTag.gehfaehigkeit;
		}
		if (changes[6] && !changesHist[6]) {
			needToUpdate = true;
			tNewest.respiration = newTag.respiration;
		}
		if (changes[7] && !changesHist[7]) {
			needToUpdate = true;
			tNewest.perfusion = newTag.perfusion;
		}
		if (changes[8] && !changesHist[8]) {
			needToUpdate = true;
			tNewest.mentalerstatus = newTag.mentalerstatus;
		}
		
		if (changes[9] && !changesHist[9]) {
			needToUpdate = true;
			tNewest.behandlungsstatus = newTag.behandlungsstatus;
		}
		if (changes[10] && !changesHist[10]) {
			needToUpdate = true;
			tNewest.triagekategorie = newTag.triagekategorie;
		}
		if (changes[11] && !changesHist[11]) {
			needToUpdate = true;
			tNewest.gps_longitude = newTag.gps_longitude;
		}
		if (changes[12] && !changesHist[12]) {
			needToUpdate = true;
			tNewest.gps_latitude = newTag.gps_latitude;
		}
		if (changes[13] && !changesHist[13]) {
			needToUpdate = true;
			tNewest.gps_accuracy = newTag.gps_accuracy;
		}
		if (changes[14] && !changesHist[14]) {
			needToUpdate = true;
			tNewest.lebensphase = newTag.lebensphase;
		}
		if (changes[15] && !changesHist[15]) {
			needToUpdate = true;
			tNewest.bergeinformation = newTag.bergeinformation;
		}
		if (changes[16] && !changesHist[16]) {
			needToUpdate = true;
			tNewest.hilfplatzposition = newTag.hilfplatzposition;
		}
		if (changes[17] && !changesHist[17]) {
			needToUpdate = true;
			tNewest.urgency = newTag.urgency;
		}
		if (changes[18] && !changesHist[18]) {
			needToUpdate = true;
			tNewest.diagnosis = newTag.diagnosis;
		}
		if (changes[19] && !changesHist[19]) {
			needToUpdate = true;
			tNewest.blood_pressure_systolic = newTag.blood_pressure_systolic;
		}
		if (changes[20] && !changesHist[21]) {
			needToUpdate = true;
			tNewest.blood_pressure_diastolic = newTag.blood_pressure_diastolic;
		}
		if (changes[21] && !changesHist[21]) {
			needToUpdate = true;
			tNewest.puls = newTag.puls;
		}
		if (changes[22] && !changesHist[22]) {
			needToUpdate = true;
			tNewest.behandlungsverlauf = newTag.behandlungsverlauf;
		}
		if (changes[23] && !changesHist[23]) {
			needToUpdate = true;
			tNewest.transportbereitschaft = newTag.transportbereitschaft;
		}
		if (changes[24] && !changesHist[24]) {
			needToUpdate = true;
			tNewest.zielkrankenhaus = newTag.zielkrankenhaus;
		}
		if (changes[25] && !changesHist[25]) {
			needToUpdate = true;
			tNewest.krankenkasse = newTag.krankenkasse;
		}
		
		for (Entry<BodyPart, String> entry : newTag.getVerletzungen().entrySet()) {
			tNewest.setVerletzung(entry.getKey(), entry.getValue());
			needToUpdate = true;
		}
		
		if (needToUpdate) {
			tNewest.setAuthor_uid(newTag.author_uid);
			tNewest.setAuthor_family(newTag.author_family);
			tNewest.setAuthor_given(newTag.author_given);
			tNewest.setDocument_parent_vnr(tNewest.getDocument_vnr());
			tNewest.setDocument_vnr(tNewest.getDocument_vnr()+1);
			return tNewest;
		}
		return null;
	}
	
	/**
	 * Helper method for @see {@link TriageTag#integrateChanges(TriageTag[], TriageTag)}. Returns a boolean
	 * which shows, which fields differ from a TriageTag t1 to a TriageTag t2. If a specific data-field from
	 * t1 differs from t2, it's index will be flagged with true in the returned boolean array.
	 * 
	 * @param diff 26-slot boolean array
	 * @param t1 see description
	 * @param t2 see description
	 * @return 26-slot boolean array, characterizing the difference between t1 and t2 data-fields
	 */
	private static boolean[] difference(boolean[] diff, TriageTag t1, TriageTag t2) {
		
		if (!t1.given.equals(t2.given)) {
			diff[0] = true;
		}
		if (!t1.family.equals(t2.family)) {
			diff[1] = true;
		}
		if (t1.gender != t2.gender) {
			diff[2] = true;
		}
		
		int day = Calendar.DAY_OF_MONTH;
		int month = Calendar.MONTH;
		int year = Calendar.YEAR;
		if (t1.birthdate.get(day) != t2.birthdate.get(day) || t1.birthdate.get(month) != t2.birthdate.get(month) || t1.birthdate.get(year) != t2.birthdate.get(year)) {
			diff[3] = true;
		}
		//Does not matter
		/*if (!t1.author_uid.equals(t2.author_uid)) {
			diff[4] = true;
		}*/
		if (t1.gehfaehigkeit != t2.gehfaehigkeit) {
			diff[5] = true;
		}
		if (t1.respiration != t2.respiration) {
			diff[6] = true;
		}
		if (t1.perfusion != t2.perfusion) {
			diff[7] = true;
		}
		if (t1.mentalerstatus != t2.mentalerstatus) {
			diff[8] = true;
		}
		if (t1.behandlungsstatus != t2.behandlungsstatus) {
			diff[9] = true;
		}
		if (t1.triagekategorie != t2.triagekategorie) {
			diff[10] = true;
		}

		//Upfollowing fields are optional, so we have to care about NULL values

		if (t1.gps_longitude != t2.gps_longitude) {
			diff[11] = true;
		}
		if (t1.gps_latitude != t2.gps_latitude) {
			diff[12] = true;
		}
		if (t1.gps_accuracy != t2.gps_accuracy) {
			diff[13] = true;
		}
		if (t1.lebensphase != t2.lebensphase) {
			diff[14] = true;
		}
		
		//Strings are complicated with NULL values ...
		if (t1.bergeinformation != null && t2.bergeinformation != null) {
			if (!t1.bergeinformation.equals(t2.bergeinformation)) {
				diff[15] = true;
			}
		} else if (t1.bergeinformation != t2.bergeinformation) {
			diff[15] = true;
		}
		if (t1.hilfplatzposition != null && t2.hilfplatzposition != null) {
			if (!t1.hilfplatzposition.equals(t2.hilfplatzposition)) {
				diff[16] = true;
			}
		} else if (t1.hilfplatzposition != t2.hilfplatzposition) {
			diff[16] = true;
		}
		
		if (t1.urgency != t2.urgency) {
			diff[17] = true;
		}
		
		//Strings
		if (t1.diagnosis != null && t2.diagnosis != null) {
			if (!t1.diagnosis.equals(t2.diagnosis)) {
				diff[18] = true;
			}
		} else if (t1.diagnosis != t2.diagnosis) {
			diff[18] = true;
		}
		

		if (t1.blood_pressure_systolic != t2.blood_pressure_systolic) {
			diff[19] = true;
		}
		if (t1.blood_pressure_diastolic != t2.blood_pressure_diastolic) {
			diff[20] = true;
		}
		
		if (t1.puls != t2.puls) {
			diff[21] = true;
		}
		
		//Strings
		if (t1.behandlungsverlauf != null && t2.behandlungsverlauf != null) {
			if (!t1.behandlungsverlauf.equals(t2.behandlungsverlauf)) {
				diff[22] = true;
			}
		} else if (t1.behandlungsverlauf != t2.behandlungsverlauf) {
			diff[22] = true;
		}
		
		if (t1.transportbereitschaft != t2.transportbereitschaft) {
			diff[23] = true;
		}
		
		//Strings
		if (t1.zielkrankenhaus != null && t2.zielkrankenhaus != null) {
			if (!t1.zielkrankenhaus.equals(t2.zielkrankenhaus)) {
				diff[24] = true;
			}
		} else if (t1.zielkrankenhaus != t2.zielkrankenhaus) {
			diff[24] = true;
		}
		if (t1.krankenkasse != null && t2.krankenkasse != null) {
			if (!t1.krankenkasse.equals(t2.krankenkasse)) {
				diff[25] = true;
			}
		} else if (t1.krankenkasse != t2.krankenkasse) {
			diff[25] = true;
		}

		return diff;
	}
	
	@Override
	public String toString() {
		return "TriageTag [document_uid=" + document_uid + ", document_vnr="
				+ document_vnr + ", document_parent_uid=" + document_parent_uid
				+ ", document_parent_vnr=" + document_parent_vnr
				+ ", effectiveTime=" + effectiveTime.getTime().toString() + ", given=" + given
				+ ", family=" + family + ", gender=" + gender + ", birthdate="
				+ birthdate.getTime().toString() + ", author_uid=" + author_uid + ", author_given="
				+ author_given + ", author_family=" + author_family
				+ ", gehfaehigkeit=" + gehfaehigkeit + ", respiration="
				+ respiration + ", perfusion=" + perfusion
				+ ", mentalerstatus=" + mentalerstatus + ", behandlungsstatus="
				+ behandlungsstatus + ", triagekategorie=" + triagekategorie
				+ ", gps_longitude=" + gps_longitude + ", gps_latitude="
				+ gps_latitude + ", gps_accuracy=" + gps_accuracy
				+ ", lebensphase=" + lebensphase + ", hilfplatzposition="
				+ hilfplatzposition + ", bergeinformation=" + bergeinformation
				+ ", urgency=" + urgency + ", diagnosis=" + diagnosis
				+ ", blood_pressure_systolic=" + blood_pressure_systolic
				+ ", blood_pressure_diastolic=" + blood_pressure_diastolic
				+ ", puls=" + puls + ", behandlungsverlauf="
				+ behandlungsverlauf + ", transportbereitschaft="
				+ transportbereitschaft + ", zielkrankenhaus="
				+ zielkrankenhaus + ", krankenkasse=" + krankenkasse
				+ ", verletzungen=" + verletzungen + "]";
	}

	public enum Gender {
		MALE("M"), FEMALE("F");
		
		private final String text;
		 /**
	     * @param text
	     */
	    private Gender(final String text) {
	        this.text = text;
	    }

	    public static Gender getFromString(String in) {
	    	if (in.equalsIgnoreCase(MALE.toString())) {
	    		return MALE;
	    	}
	    	if (in.equalsIgnoreCase(FEMALE.toString())) {
	    		return FEMALE;
	    	}
	    	return null;
	    }
	    
	    /* (non-Javadoc)
	     * @see java.lang.Enum#toString()
	     */
	    @Override
	    public String toString() {
	        return text;
	    }
	}
	
	public enum Stability {
		STABLE("stabil"), CRITICAL("kritisch");
		private final String text;
		 /**
	     * @param text
	     */
	    private Stability(final String text) {
	        this.text = text;
	    }
	    
	    public static Stability getFromString(String in) {
	    	if (in.equalsIgnoreCase(STABLE.toString())) {
	    		return STABLE;
	    	}
	    	if (in.equalsIgnoreCase(CRITICAL.toString())) {
	    		return CRITICAL;
	    	}
	    	return null;
	    }

	    /* (non-Javadoc)
	     * @see java.lang.Enum#toString()
	     */
	    @Override
	    public String toString() {
	        return text;
	    }
	}
	
	public enum TriageCategory {
		IMMEDIATE("immediate"), DELAYED("delayed"), MINOR("minor"), DECEASED("deceased");
		
		private final String text;
		 /**
	     * @param text
	     */
	    private TriageCategory(final String text) {
	        this.text = text;
	    }
	    
	    public static TriageCategory getFromString(String in) {
	    	if (in.equalsIgnoreCase(IMMEDIATE.toString())) {
	    		return IMMEDIATE;
	    	}
	    	if (in.equalsIgnoreCase(DELAYED.toString())) {
	    		return DELAYED;
	    	}
	    	if (in.equalsIgnoreCase(MINOR.toString())) {
	    		return MINOR;
	    	}
	    	if (in.equalsIgnoreCase(DECEASED.toString())) {
	    		return DECEASED;
	    	}
	    	return null;
	    }

	    /* (non-Javadoc)
	     * @see java.lang.Enum#toString()
	     */
	    @Override
	    public String toString() {
	        return text;
	    }
	}
	
	public enum PhaseOfLife {
		CHILD("Kind"), ADULT("Erwachsen");
		
		private final String text;
		 /**
	     * @param text
	     */
	    private PhaseOfLife(final String text) {
	        this.text = text;
	    }
	    
	    public static PhaseOfLife getFromString(String in) {
	    	if (in == null) {
	    		return null;
	    	}
	    	if (in.equalsIgnoreCase(CHILD.toString())) {
	    		return CHILD;
	    	}
	    	if (in.equalsIgnoreCase(ADULT.toString())) {
	    		return ADULT;
	    	}
	    	return null;
	    }

	    /* (non-Javadoc)
	     * @see java.lang.Enum#toString()
	     */
	    @Override
	    public String toString() {
	        return text;
	    }
	}
	
	public enum TreatmentStatus {
		
		UNDEFINED("undefiniert"), SIGHTED("gesichtet"), RESCUED("geborgen"), EVACUATED("abtransportiert");
		private final String text;
		 /**
	     * @param text
	     */
	    private TreatmentStatus(final String text) {
	        this.text = text;
	    }
	    
	    public static TreatmentStatus getFromString(String in) {
	    	if (in.equalsIgnoreCase(UNDEFINED.toString())) {
	    		return UNDEFINED;
	    	}
	    	if (in.equalsIgnoreCase(SIGHTED.toString())) {
	    		return SIGHTED;
	    	}
	    	if (in.equalsIgnoreCase(RESCUED.toString())) {
	    		return RESCUED;
	    	}
	    	if (in.equalsIgnoreCase(EVACUATED.toString())) {
	    		return EVACUATED;
	    	}
	    	return null;
	    }

	    /* (non-Javadoc)
	     * @see java.lang.Enum#toString()
	     */
	    @Override
	    public String toString() {
	        return text;
	    }
	}
	
	public enum BodyPart {
		
		VORNE_KOPF("Vorne_Kopf"),		
    	VORNE_HALS("Vorne_Hals"),
    	VORNE_BRUST("Vorne_Brust"),
    	VORNE_BAUCH("Vorne_Bauch"),
    	VORNE_ROBERARM("Vorne_ROberarm"),
    	VORNE_LOBERARM("Vorne_LOberarm"),
    	VORNE_RUNTERARM("Vorne_RUnterarm"),
    	VORNE_LUNTERARM("Vorne_LUnterarm"),
    	VORNE_RHAND("Vorne_RHand"),
    	VORNE_LHAND("Vorne_LHand"),
    	VORNE_LOBERSCHENKEL("Vorne_LOberschenkel"),
    	VORNE_ROBERSCHENKEL("Vorne_ROberschenkel"),
    	VORNE_LUNTERSCHENKEL("Vorne_LUnterschenkel"),
    	VORNE_RUNTERSCHENKEL("Vorne_RUnterschenkel"),
    	VORNE_LFUSS("Vorne_LFuss"),
    	VORNE_RFUSS("Vorne_RFuss"),
		HINTEN_KOPF("Hinten_Kopf"),		
    	HINTEN_HALS("Hinten_Hals"),
    	HINTEN_BRUST("Hinten_Brust"),
    	HINTEN_BAUCH("Hinten_Bauch"),
    	HINTEN_ROBERARM("Hinten_ROberarm"),
    	HINTEN_LOBERARM("Hinten_LOberarm"),
    	HINTEN_RUNTERARM("Hinten_RUnterarm"),
    	HINTEN_LUNTERARM("Hinten_LUnterarm"),
    	HINTEN_RHAND("Hinten_RHand"),
    	HINTEN_LHAND("Hinten_LHand"),
    	HINTEN_LOBERSCHENKEL("Hinten_LOberschenkel"),
    	HINTEN_ROBERSCHENKEL("Hinten_ROberschenkel"),
    	HINTEN_LUNTERSCHENKEL("Hinten_LUnterschenkel"),
    	HINTEN_RUNTERSCHENKEL("Hinten_RUnterschenkel"),
    	HINTEN_LFUSS("Hinten_LFuss"),
    	HINTEN_RFUSS("Hinten_RFuss");
		
		public static String[] toStringArray() {
			return new String[] { "Vorne_Kopf", "Vorne_Hals", "Vorne_Brust",
					"Vorne_Bauch", "Vorne_ROberarm", "Vorne_LOberarm", "Vorne_RUnterarm",
					"Vorne_LUnterarm", "Vorne_RHand", "Vorne_LHand", "Vorne_LOberschenkel",
					"Vorne_ROberschenkel", "Vorne_LUnterschenkel", "Vorne_RUnterschenkel",
					"Vorne_LFuss", "Vorne_RFuss", "Hinten_Kopf", "Hinten_Hals", "Hinten_Brust",
					"Hinten_Bauch", "Hinten_ROberarm", "Hinten_LOberarm", "Hinten_RUnterarm",
					"Hinten_LUnterarm", "Hinten_RHand", "Hinten_LHand", "Hinten_LOberschenkel",
					"Hinten_ROberschenkel", "Hinten_LUnterschenkel", "Hinten_RUnterschenkel",
					"Hinten_LFuss", "Hinten_RFuss"};
		}
    	
		private final String text;
		 /**
	     * @param text
	     */
	    private BodyPart(final String text) {
	        this.text = text;
	    }

	    public static BodyPart getFromString(String in) {
	    	if (in.equalsIgnoreCase(VORNE_KOPF.toString())) {
	    		return VORNE_KOPF;
	    	}
	    	if (in.equalsIgnoreCase(VORNE_HALS.toString())) {
	    		return VORNE_HALS;
	    	}
	    	if (in.equalsIgnoreCase(VORNE_BRUST.toString())) {
	    		return VORNE_BRUST;
	    	}
	    	if (in.equalsIgnoreCase(VORNE_BAUCH.toString())) {
	    		return VORNE_BAUCH;
	    	}
	    	if (in.equalsIgnoreCase(VORNE_ROBERARM.toString())) {
	    		return VORNE_ROBERARM;
	    	}
	    	if (in.equalsIgnoreCase(VORNE_LOBERARM.toString())) {
	    		return VORNE_LOBERARM;
	    	}
	    	if (in.equalsIgnoreCase(VORNE_RUNTERARM.toString())) {
	    		return VORNE_RUNTERARM;
	    	}
	    	if (in.equalsIgnoreCase(VORNE_LUNTERARM.toString())) {
	    		return VORNE_LUNTERARM;
	    	}
	    	if (in.equalsIgnoreCase(VORNE_RHAND.toString())) {
	    		return VORNE_RHAND;
	    	}
	    	if (in.equalsIgnoreCase(VORNE_LHAND.toString())) {
	    		return VORNE_LHAND;
	    	}
	    	if (in.equalsIgnoreCase(VORNE_ROBERSCHENKEL.toString())) {
	    		return VORNE_ROBERSCHENKEL;
	    	}
	    	if (in.equalsIgnoreCase(VORNE_LOBERSCHENKEL.toString())) {
	    		return VORNE_LOBERSCHENKEL;
	    	}
	    	if (in.equalsIgnoreCase(VORNE_RUNTERSCHENKEL.toString())) {
	    		return VORNE_RUNTERSCHENKEL;
	    	}
	    	if (in.equalsIgnoreCase(VORNE_LUNTERSCHENKEL.toString())) {
	    		return VORNE_LUNTERSCHENKEL;
	    	}
	    	if (in.equalsIgnoreCase(VORNE_RFUSS.toString())) {
	    		return VORNE_RFUSS;
	    	}
	    	if (in.equalsIgnoreCase(VORNE_LFUSS.toString())) {
	    		return VORNE_LFUSS;
	    	}
	    	if (in.equalsIgnoreCase(HINTEN_KOPF.toString())) {
	    		return HINTEN_KOPF;
	    	}
	    	if (in.equalsIgnoreCase(HINTEN_HALS.toString())) {
	    		return HINTEN_HALS;
	    	}
	    	if (in.equalsIgnoreCase(HINTEN_BRUST.toString())) {
	    		return HINTEN_BRUST;
	    	}
	    	if (in.equalsIgnoreCase(HINTEN_BAUCH.toString())) {
	    		return HINTEN_BAUCH;
	    	}
	    	if (in.equalsIgnoreCase(HINTEN_ROBERARM.toString())) {
	    		return HINTEN_ROBERARM;
	    	}
	    	if (in.equalsIgnoreCase(HINTEN_LOBERARM.toString())) {
	    		return HINTEN_LOBERARM;
	    	}
	    	if (in.equalsIgnoreCase(HINTEN_RUNTERARM.toString())) {
	    		return HINTEN_RUNTERARM;
	    	}
	    	if (in.equalsIgnoreCase(HINTEN_LUNTERARM.toString())) {
	    		return HINTEN_LUNTERARM;
	    	}
	    	if (in.equalsIgnoreCase(HINTEN_RHAND.toString())) {
	    		return HINTEN_RHAND;
	    	}
	    	if (in.equalsIgnoreCase(HINTEN_LHAND.toString())) {
	    		return HINTEN_LHAND;
	    	}
	    	if (in.equalsIgnoreCase(HINTEN_ROBERSCHENKEL.toString())) {
	    		return HINTEN_ROBERSCHENKEL;
	    	}
	    	if (in.equalsIgnoreCase(HINTEN_LOBERSCHENKEL.toString())) {
	    		return HINTEN_LOBERSCHENKEL;
	    	}
	    	if (in.equalsIgnoreCase(HINTEN_RUNTERSCHENKEL.toString())) {
	    		return HINTEN_RUNTERSCHENKEL;
	    	}
	    	if (in.equalsIgnoreCase(HINTEN_LUNTERSCHENKEL.toString())) {
	    		return HINTEN_LUNTERSCHENKEL;
	    	}
	    	if (in.equalsIgnoreCase(HINTEN_RFUSS.toString())) {
	    		return HINTEN_RFUSS;
	    	}
	    	if (in.equalsIgnoreCase(HINTEN_LFUSS.toString())) {
	    		return HINTEN_LFUSS;
	    	}
	    	return null;
	    }
	    
	    /* (non-Javadoc)
	     * @see java.lang.Enum#toString()
	     */
	    @Override
	    public String toString() {
	        return text;
	    }
	}
	
	
}


